package com.piece.core.session.repository;

import lombok.Setter;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.session.data.redis.RedisFlushMode;

@Setter
public class SessionRepositoryManager {

    private RedisSerializer<Object> defaultRedisSerializer = new JdkSerializationRedisSerializer();
    private Integer maxInactiveIntervalInSeconds = 1800;
    private String redisNamespace = "spring:session";
    private RedisFlushMode redisFlushMode;
    private int database;
    private RedisTemplate redisTemplate;
    private ApplicationEventPublisher applicationEventPublisher;
    private SessionRepository sessionRepository;

    public SessionRepositoryManager(SessionRepository sessionRepository) {
        this.sessionRepository = sessionRepository;
    }

    public SessionRepository getSessionRepository() {
        sessionRepository.setMaxInactiveIntervalInSeconds(maxInactiveIntervalInSeconds);
        sessionRepository.setRedisNamespace(redisNamespace);
        sessionRepository.setRedisFlushMode(redisFlushMode);
        sessionRepository.setDatabase(database);
        sessionRepository.setRedisTemplate(redisTemplate);
        sessionRepository.setApplicationEventPublisher(applicationEventPublisher);
        sessionRepository.setDefaultRedisSerializer(defaultRedisSerializer);
        sessionRepository.setSessionRedisOperations(redisTemplate);
        return sessionRepository;
    }
}
